package ar.uba.fi.taller2.jh.BPBasicTree;

import java.util.*;

import ar.uba.fi.taller2.jh.Tree.*;

/*****************************************************************************
 * @author Sebastian rivas
 * @version 1.0
 * 
 ****************************************************************************/

public abstract class BPBasicLeafNode extends LeafNode {
  
  /****************************************************************************
   * CONSTRUCTOR
   *
   * @param comp Comparator
   * @param n_recs int
   ***************************************************************************/

  public BPBasicLeafNode(Comparator comp,int n_recs, boolean _isRoot, Tree _tree) {
	super(comp, n_recs, _isRoot, _tree);
  }

  /****************************************************************************
   * CONSTRUCTOR
   *
   * @param o BPBasicLeafNode
   ***************************************************************************/

  public BPBasicLeafNode(BPBasicLeafNode o) {
	super(o);
  }

  /****************************************************************************
   *
   * @param o Object
   *  append a child or record to the end
   ***************************************************************************/
  public void append(Object o, Object key){

	  copyRecord(rsize,(Tree.Entry)o);
	  rsize++;
   }

   /****************************************************************************
    *
    * @param o Object
    *  puts something at the beginning of the children or records
    ***************************************************************************/
   public void putFirst(Object o, Object key){
     copyRecord(0,(Tree.Entry)o);
   }

  // Concatena el nodo next
  public void concat(Node next, Object key) {
	  
	  BPBasicLeafNode nextAux = (BPBasicLeafNode)next;
	  for(int i=0; i<nextAux.size(); i++) {
		  this.copyRecord(rsize+i, nextAux.records[i]);
	  }
	  this.rsize = this.size()+nextAux.size();
	  nextAux.tree.getDisk().releaseBlock(this.getId());
  }
  
  public Object getPromoted(int pos) {
	  return null;
  }
}